x11: Detect single-touch touchscreens as GDK_SOURCE_TOUCHSCREEN
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 30 Oct 2015 13:10:19 +0000 (14:10 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 3 Nov 2015 12:07:12 +0000 (07:07 -0500)
Those won't have ABS_MT_* axes, so won't be reported has having
XITouchClassInfo. Fallback on these to checking whether abs x/y axes are
available. After the Wacom checks, any remaining device with absolute axes
should be touchscreens, and GDK_SOURCE_MOUSE does indeed just make sense on
devices with relative axes.

https://bugzilla.gnome.org/show_bug.cgi?id=757358

gdk/x11/gdkdevicemanager-xi2.c

index 2401ff1ce76f37bc60f2f80aca1f56f4255378b1..dc35f0310e1427ed3fddaf5758de54f44288d1d7 100644 (file)
@@ -301,6 +301,39 @@ is_touch_device (XIAnyClassInfo **classes,
   return FALSE;
 }
 
+static gboolean
+has_abs_axes (GdkDisplay      *display,
+              XIAnyClassInfo **classes,
+              guint            n_classes)
+{
+  gboolean has_x = FALSE, has_y = FALSE;
+  Atom abs_x, abs_y;
+  guint i;
+
+  abs_x = gdk_x11_get_xatom_by_name_for_display (display, "Abs X");
+  abs_y = gdk_x11_get_xatom_by_name_for_display (display, "Abs Y");
+
+  for (i = 0; i < n_classes; i++)
+    {
+      XIValuatorClassInfo *class = (XIValuatorClassInfo *) classes[i];
+
+      if (class->type != XIValuatorClass)
+        continue;
+      if (class->mode != XIModeAbsolute)
+        continue;
+
+      if (class->label == abs_x)
+        has_x = TRUE;
+      else if (class->label == abs_y)
+        has_y = TRUE;
+
+      if (has_x && has_y)
+        break;
+    }
+
+  return (has_x && has_y);
+}
+
 static gboolean
 get_device_ids (GdkDisplay    *display,
                 XIDeviceInfo  *info,
@@ -393,6 +426,8 @@ create_device (GdkDeviceManager *device_manager,
       else if (strstr (tmp_name, "wacom") ||
                strstr (tmp_name, "pen"))
         input_source = GDK_SOURCE_PEN;
+      else if (has_abs_axes (display, dev->classes, dev->num_classes))
+        input_source = GDK_SOURCE_TOUCHSCREEN;
       else
         input_source = GDK_SOURCE_MOUSE;